package com.itheima.常用API.object;

import java.util.Objects;

public class 方法equals {
    public static void main(String[] args) {
        Stu s1=new Stu();
        Stu s2=new Stu();
        System.out.println(s1==s2);
        System.out.println(s1.equals(s2));
    }
}
class Stu{
    String name="hello world........";
    int age;

    @Override
     public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || this.getClass() != o.getClass()) return false;
        Stu stu = (Stu) o;
        return age == stu.age &&
                Objects.equals(name, stu.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Stu{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}